#pragma once
#include <semaphore.h>
#include "Uart.h"
#include "Lock.h"

class XRequest : public IOnRecv
{
public:
	XRequest();
	virtual ~XRequest(void);
	bool Open();
	bool IsOpen();
	void Close();
	virtual void OnRecv(const unsigned char* pBuf, int length);
	bool Request(const unsigned char* pBuf, int length, bool waitResp = true);
private:
	void Notify();
	int Wait(int timeout);
	void RequestInner(const unsigned char* pBuf, int length, bool waitResp);
private:
	Uart m_Uart;;
	unsigned char m_RespResult;
	CLock m_Lock;
	sem_t m_hSem;
	bool  m_bInReq;
};
